$(warning $(shell mysql --version))

MYSQL_PASSWORD:= 'RxJa%%^@()va2017'


mysql.out: $(HOME)/mysql/mysql.version
	cp $< $@


/usr/bin/mysql: mysql57-community-release-el7-11.noarch.rpm
	yum -y localinstall $<
	yum -y update
	yum -y install mysql-community-server
	systemctl disable mysqld
	systemctl enable mysqld
	systemctl daemon-reload
	systemctl start mysqld
	systemctl status mysqld
	mysql --version


mysql57-community-release-el7-11.noarch.rpm:
	wget https://repo.mysql.com/mysql57-community-release-el7-11.noarch.rpm



mysql.password: /usr/bin/mysql
	echo "ALTER USER 'root'@'localhost' IDENTIFIED BY $(MYSQL_PASSWORD);GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY $(MYSQL_PASSWORD) WITH GRANT OPTION;FLUSH PRIVILEGES;"
	grep 'temporary password' /var/log/mysqld.log
	mysql -u root -p 
	echo "$(MYSQL_PASSWORD)" > $@


$(HOME)/mysql/mysql.version: mysql.password
	systemctl stop mysqld
	cp -af /var/lib/mysql $(HOME)/
	mv /var/lib/mysql /var/lib/mysql~
	ln -s $(HOME)/mysql /var/lib/mysql
	systemctl start mysqld
	mysql --version > $@


